static inline int LMath::CompareMagnitudes(const LInteger& a, const LInteger& b)
Returns a positive, zero, or negative integer if a
is
greater than, equal to, or less than b
, respectively.
static inline LInteger LMath::Negative(const LInteger& a)
Returns a LInteger
equal to the product of -1 and
a
.
static inline LInteger LMath::AbsoluteValue(const LInteger& a)
Returns a LInteger
equal to the absolute value of
a
.
static LInteger LMath::TwoToThe(const int power)
Returns a LInteger
equal to 2 raised to the power of
power
. power
must be non-negative.
static void LMath::LongDivide(const LInteger& divisor, const LInteger& dividend,
LInteger& Quotient, LInteger& Remainder)
Sets Quotient
and Remainder
such that
dividend=Quotient*divisor+Remainder
, with
0<=Remainder<|divisor|
.
Note: This function will probably be named "EuclideanDivision" in later release of this library, and the order of the first two arguments may be changed.
static LInteger LMath::ModExp(const LInteger& g, const LInteger& x, const LInteger& n)
Returns a LInteger
representing the integer between 0 and
|n|-1
which is congruent, mod n
, to
g
raised to the the x
th power.
static LInteger LMath::SpecialModExp(const LInteger& g, const LInteger& x, const LInteger& n)
Returns a LInteger
representing the integer between 0 and
n-1
which is congruent, mod n
, to
g
raised to the the x
th power. This method
only works for certain g
, x
, and n
:
g
must be non-negative; x
must be positive;
n
must be odd and greater than 1. This method is
faster than ModExp
for large values of
x
. (The turn over pointed has not been determined, yet,
but it is certainly faster for 512+ bit g
,
x
, and n
on my i486 DX/2.)
static LInteger LMath::ExtendedEuclid(const LInteger& a, const LInteger& b,
LInteger& u, LInteger& v)
Sets u
and v
to values such that
a*u+b*v
is equal to the greatest common divisor
of a
and b
, and returns a LInteger
representing this greatest common divisor.